export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const resourceId = query.resourceId;

  // 模拟从数据库查询属性Schema
  const mockSchemas = [
    {
      id: '1',
      resourceId: '1',
      type: 'manual',
      schema: {
        fields: [
          {
            name: 'roomNumber',
            label: '房间号',
            type: 'TEXT',
            required: true,
            defaultValue: '',
          },
          {
            name: 'floor',
            label: '楼层',
            type: 'NUMBER',
            required: true,
            defaultValue: 1,
          },
          {
            name: 'status',
            label: '状态',
            type: 'SELECT',
            required: true,
            options: [
              { label: '空闲', value: 'available' },
              { label: '已预订', value: 'booked' },
              { label: '已入住', value: 'occupied' },
            ],
            defaultValue: 'available',
          },
        ],
      },
      options: {},
      createTime: 1703123456789,
      updateTime: 1703123456789,
    },
    {
      id: '2',
      resourceId: '2',
      type: 'vbenform',
      schema: [
        {
          component: 'Input',
          componentProps: {
            placeholder: '请输入房间号',
          },
          fieldName: 'roomNumber',
          label: '房间号',
          rules: 'required',
        },
        {
          component: 'InputNumber',
          componentProps: {
            placeholder: '请输入楼层',
            min: 1,
            max: 100,
          },
          fieldName: 'floor',
          label: '楼层',
          rules: 'required',
        },
        {
          component: 'Select',
          componentProps: {
            placeholder: '请选择状态',
            options: [
              { label: '空闲', value: 'available' },
              { label: '已预订', value: 'booked' },
              { label: '已入住', value: 'occupied' },
            ],
          },
          fieldName: 'status',
          label: '状态',
          rules: 'required',
        },
      ],
      options: {
        submitBtn: true,
        resetBtn: true,
      },
      createTime: 1703123456789,
      updateTime: 1703123456789,
    },
    {
      id: '3',
      resourceId: '3',
      type: 'formcreate',
      schema: {
        rules: [
          {
            type: 'input',
            field: 'roomNumber',
            title: '房间号',
            props: {
              placeholder: '请输入房间号',
            },
            validate: [{ required: true, message: '请输入房间号' }],
          },
          {
            type: 'number',
            field: 'floor',
            title: '楼层',
            props: {
              placeholder: '请输入楼层',
              min: 1,
              max: 100,
            },
            validate: [{ required: true, message: '请输入楼层' }],
          },
          {
            type: 'select',
            field: 'status',
            title: '状态',
            props: {
              placeholder: '请选择状态',
            },
            options: [
              { label: '空闲', value: 'available' },
              { label: '已预订', value: 'booked' },
              { label: '已入住', value: 'occupied' },
            ],
            validate: [{ required: true, message: '请选择状态' }],
          },
        ],
      },
      options: {
        submitBtn: false,
        resetBtn: false,
        formData: {},
      },
      createTime: 1703123456789,
      updateTime: 1703123456789,
    },
  ];

  // 根据resourceId查找对应的Schema
  const schema = mockSchemas.find((s) => s.resourceId === resourceId);

  return {
    code: 200,
    data: schema || null,
    message: schema ? '查询成功' : '未找到对应的属性Schema',
  };
});
